//
//  TextFieldTableViewCell.m
//  Rail
//
//  Created by hychen on 2018/3/18.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "TextFieldTableViewCell.h"

@interface TextFieldTableViewCell ()<UITextFieldDelegate>
@property (nonatomic, strong) UILabel *titleLabel;

@end
@implementation TextFieldTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self showBottomLineWithPaddingX:15 color:nil];
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.titleLabel = [UILabel labelWithText:@"" textColor:Color_RGB(44, 44, 44) font:[UIFont systemFontOfSize:18.f]];
    [self.contentView addSubview:self.titleLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.equalTo(self.contentView);
    }];
    
    self.tf = [UITextField new];
    self.tf.textAlignment = NSTextAlignmentRight;
    self.tf.font = [UIFont systemFontOfSize:14];
    [self.tf setDelegate:self];
    [self.contentView addSubview:self.tf];
    [self.tf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.contentView);
    }];
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (self.BlockEndEditing) {
        self.BlockEndEditing(textField.text);
    }
}

- (void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

- (void)setContent:(NSString *)content {
    _content = content;
    self.tf.text = content;
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    self.tf.placeholder = placeholder;
}

@end
